<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="1200" destroy-on-close @closed="$emit('closed')" :align-center="true">
        <el-container>
            <el-main>
                <el-form-item prop="process_data">
                    <sc-form-table ref="table" v-model="form.process_data" :addTemplate="process" placeholder="暂无数据" hideAdd hideDelete>
                        <el-table-column prop="process_id" label="一级工序" align="center">
                            <template #default="scope">
                                <div>
                                    {{scope.row.process_title}}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="GongxuSon" label="二级工序" align="center">
                            <template #default="scope">
                                <div>
                                    {{scope.row.two_process_title}}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="price" label="报工单价" align="center">
                            <template #default="scope">
                                <div>
                                    {{scope.row.price}}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="price" label="员工姓名" align="center">
                            <template #default="scope">
                                <div>
                                    {{scope.row.price}}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="price" label="报工时间" align="center">
                            <template #default="scope">
                                <div>
                                    {{scope.row.price}}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="price" label="报工数量" align="center">
                            <template #default="scope">
                                <div>
                                    {{scope.row.price}}
                                </div>
                            </template>
                        </el-table-column>
                    </sc-form-table>
                </el-form-item>
            </el-main>
            <el-footer>
                <div style="display: flex;justify-content: end;">
                    <el-button @click="visible=false" >取 消</el-button>
                    <el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">完 成</el-button>
                </div>
            </el-footer>
        </el-container>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '添加客户',
					edit: '编辑客户',
					show: '详情'
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					id:"",
                    needle_seed:"",
                    loom_time:"",
                    process_data:[]
				},
				//验证规则
				rules: {
                    needle_seed: [
						{required: true, message: '请选择'}
					],
                    loom_time: [
						{required: true, message: '请输入织机时间'}
					],
				},
                process:{process_id:"",price:""},
                needleList:[],//针种
			}
		},
		mounted() {
            this.getNeedle()
		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.isSaveing = true;
						var res  = [];
						res = await this.$API.develop.edition.complete.post(this.form);
						this.isSaveing = false;
						if(res.code == 1){
							this.$emit('success', this.form, this.mode)
							this.visible = false;
							this.$message.success("操作成功")
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}else{
						return false;
					}
				})
			},
			//表单注入数据
			async setData(data){
                this.form.id = data.id
                var res = await this.$API.develop.edition.detail.get({id:data.id});
                let a = []
                res.data.process.map(item=>{
                    a.push({
                        id:item.id,
                        process_id:item.process_id,
                        process_title:item.process_title,
                        two_process_title:item.two_process_title,
                        price:item.price,
                        
                    })
                })
                this.form.process_data = a
			},
            //所有针种
            async getNeedle(){
                var res = await this.$API.all.needle.get();
                this.needleList = res.data;
            },
		}
	}
</script>

<style lang="scss">
.el-form-item--default{
    align-items: center;
}
</style>
